
usrName = Sys.getenv("USER")
if (usrName =='kacper'){
  path<- '/home/kacper/dev/timeser/time-series-pred/src'
}else{
  if (usrName =='mateusz')
    path<- '/home/mateusz/workspace/TS1/time-series-pred/src'
}
if(usrName =='kc262414'){
  path <-"/home/students/mismap/k/kc262414/studia/szeregi/time-series-pred/src"
} 

setwd(path)

pps<-path
if(!exists('ownPredict', mode="function")) source("ownPredictFunction.R")
path<-pps
setwd(path)
if(!exists('ARSmoothedPredict', mode="function")) source("./PredictionMethods/ARSmoothedPredict.R")
if(!exists('MartingalePredict', mode="function")) source("./PredictionMethods/MartingalePredict.R")


#data=list(cl=cl,google=google,zf=zf)
#arMethods=c( "ols")
#arOrders =c(1,2)



ownPredDifferentTrans <- function(timeSeries,f,lookBack=10000){
  ret<-list()
  #   print('a')
  ret['noTrans']<-ownPredict(timeSeries,f,lookBack,function(x) return(x), simDeTrans)$aafe
  #   print('b')
  ret['diffTrans']<-ownPredict(timeSeries,f,lookBack,diffTransform,diffDeTransform)$aafe
  #   print('c')
  ret['LogdiffTrans']<-ownPredict(timeSeries,f,lookBack,logDiffTransform,logDiffDeTransform)$aafe
  #   print('d')
  ret['LogretTrans']<-ownPredict(timeSeries,f,lookBack,logReturnTransform,logReturnDeTransform)$aafe
  return(ret)
}



runAR <-function(timeSeries,arMethods,arOrders, lookBack=c(10000)){
  ret<- list()
  i<-1
  for (methods  in 1:length(arMethods) ){
    #     print(methods)
    for( orders in arOrders){
      for ( lookB in lookBack){
        print(paste("   runAR",orders,lookB,sep=" "));
        f<-autoregresiveCreator(orders,arMethods[methods])
        str<-paste(arMethods[methods],orders,lookB,sep="_");
        r<-ownPredDifferentTrans(timeSeries,f,lookB)
      }
      ret[[str]]<-r
    }  
  }
  return(ret)
}

runMA <-function(timeSeries){
  ret<- list()   
  str<-"mart"
  r<-ownPredDifferentTrans(timeSeries,MartingalePredict)
  ret[[str]]<-r
  return(ret)
}



#arSmoothTable = c(2,5,8)
runARsmooth <-function(timeSeries,arMethods,arOrders,arSmoothTable,lookBack=c(10000)){
  ret<- list()
  i<-1
  for (methods  in 1:length(arMethods) ){
    #     print(methods)
    for( orders in arOrders){
      print(paste("   runARsmooth",orders,sep=" "));
      for ( smooth in arSmoothTable ){
        for ( lookB in lookBack){
          #           print(smooth);print(orders);
          f<-ARSmoothedPredict(orders,arMethods[methods],smooth)
          #          f<-autoregresiveCreator(orders,arMethods[methods])
          str<-paste(arMethods[methods],orders,lookB,smooth,sep="_");
          r<-ownPredDifferentTrans(timeSeries,f,lookB)
          ret[[str]]<-r
        }
      }
    }  
  }
  return(ret)
}


#a<-runARsmooth(zf)

#printRes(a)

printRes <- function(a){
  w<-1000
  nameP<-'chooj'
  for (name in names(a)){
    x<- a[[name]]
    for ( n in names(x)){
      mp<-x[[n]]
      if(mp<w){
        #         print(name)
        #         print(n)    
        w<-mp
        nameP<-name
        #         print(w)
      }
    }
  }
  list(res=w,name=nameP)
}


#runMA(zf)






